package com.guodu.base;



import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.guodu.entity.UserInfo;
import com.opensymphony.xwork2.ActionSupport;

public class BaseAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public Long totalPage;

	public int curPage = 1;

	public int pageSize = 20;

	public int start = 0;
	


	public UserInfo userInfo;
	

	
	
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		return super.execute();
	}

	
	protected UserInfo getUser(){
		userInfo = (UserInfo) ServletActionContext.getRequest().getSession().getAttribute("userbean");
		return userInfo;
	}
	

	protected void responseStr(HttpServletResponse response,String str){
		response.setCharacterEncoding("UTF-8");
		
		try {
			PrintWriter out=response.getWriter();
			out.print(str);
			out.flush();
			out.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	protected static String toUtf8String(String s) {
		// TODO Auto-generated method stub
		StringBuffer sb = new StringBuffer(); 
	       for (int i=0;i<s.length();i++){ 
	          char c = s.charAt(i); 
	          if (c >= 0 && c <= 255){sb.append(c);} 
	        else{ 
	        byte[] b; 
	         try { b = Character.toString(c).getBytes("utf-8");} 
	         catch (Exception ex) { 
	             System.out.println(ex); 
	                  b = new byte[0]; 
	         } 
	            for (int j = 0; j < b.length; j++) { 
	             int k = b[j]; 
	              if (k < 0) k += 256; 
	              sb.append("%" + Integer.toHexString(k).toUpperCase()); 
	              } 
	     } 
	  } 
	  return sb.toString(); 
	}
	
	
	public void setStart(int start) {
		this.start = start;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public void setTotalPage(Long totalPage) {
		this.totalPage = totalPage;
	}

	
	


	public void setCurPage(int curPage) {
		this.curPage = curPage;
	}

}
